﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link href="/styles/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <script src="/js/lib/jquery.js"></script>
    <script src="/js/lib/bootstrap.js"></script>
    <script src="/js/lib/angular.js"></script>
    <script src="/js/app/Site.js"></script>
    <title>Node.js+Angularjs+MongoDB+Bootsrap</title>

   
</head>
<body style="padding:0px;margin:0px;" ng-app="app" ng-controller="appController">
    <div class="jumbotron" style="text-align: center; background-color: #080808;">
        <h1 style="color:#fff;">欢迎加入我们!</h1>
        <p style="color:#fff;">注册成为会员享受更多优惠!</p>
        <p><a class="btn btn-primary btn-lg" href="/" role="button" id="bigBtn">进入网站首页</a></p>
    </div>
    <div class="container" style="padding-bottom:10px;">
        <form name="form1">
            <div class="form-group">
                <label for="exampleInputEmail1">登录名</label>
                <input type="text" class="form-control" id="exampleInputEmail1" placeholder="只限输入英文字母(必填项)" ng-model="registObj.loginName" name="loginName" required>
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">姓名</label>
                <input type="text" class="form-control" id="exampleInputPassword1" placeholder="输入您的姓名" ng-model="registObj.userName">
            </div> 
            <div class="form-group">
                <label for="exampleInputPassword1">密码</label>
                <input type="password" class="form-control" id="exampleInputPassword1" placeholder="必填项" ng-model="registObj.password1" name="password1" required>
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">密码</label>
                <input type="password" class="form-control" id="exampleInputPassword1" placeholder="必填项" ng-model="registObj.password2" required>
            </div> 
            <div class="alert alert-danger" role="alert" ng-show="registObj.password1!=registObj.password2">
                <p><span class="glyphicon glyphicon-exclamation-sign"></span> 两次输入的密码不一致.</p>
            </div>           
            <div class="form-group">
                <label for="exampleInputPassword1">联系电话</label>
                <input type="text" class="form-control" id="exampleInputPassword1" placeholder="输入您的联系电话" ng-model="registObj.telephoe">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">联系邮箱</label>
                <input type="text" class="form-control" id="exampleInputPassword1" placeholder="输入您的邮箱" ng-model="registObj.email">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">联系QQ</label>
                <input type="text" class="form-control" id="exampleInputPassword1" placeholder="输入您的QQ" ng-model="registObj.qq">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">微信号</label>
                <input type="text" class="form-control" id="exampleInputPassword1" placeholder="输入您的微信号" ng-model="registObj.weixin">
            </div>
            <div class="form-group" ng-show="false">
                <label for="exampleInputPassword1">宝宝出生年月</label>
                <input type="text" class="form-control" id="exampleInputPassword1" placeholder="输入宝宝的生日，我们更好给你推荐拍照安排" ng-model="registObj.babyBirthday">
            </div>
            <div class="form-group" ng-show="false">
                <label for="exampleInputPassword1">宝宝性别</label>
                <input type="text" class="form-control" id="exampleInputPassword1" placeholder="输入宝宝性别" ng-model="registObj.babySex">
            </div>
            <button type="button" class="btn btn-danger" ng-click="reset()">重置</button>
            <button type="button" class="btn btn-success" ng-click="checkRegist()" ng-disabled="form1.loginName.$invalid||form1.password1.$invalid||registObj.password1!=registObj.password2">注册</button>            
        </form>
    </div>

    <section style="padding:30px; background-color: #000; text-align: center;color:#fff; ">
        <p>只为做的更好，让我们一起携手同行</p>
        <p>Copyright © 优站精选 </p>
   </section>
    <script>
        var app = angular.module("app", []);

        app.controller('appController', function ($scope, $http) {

            $scope.registObj = {};

            $scope.reset = function () {
                $scope.registObj.loginName = "";
                $scope.registObj.userName = "";
                $scope.registObj.password1 = "";
                $scope.registObj.password2 = "";
                $scope.registObj.telephoe = "";
                $scope.registObj.email = "";
                $scope.registObj.qq = "";
                $scope.registObj.weixin = "";
                $scope.registObj.babyBirthday = "";
                $scope.registObj.babySex = "";
            }
            $scope.reset();


            $scope.regist = function () {

                
                url ="/user/add";
                //alert(JSON.stringify($scope.registObj));
                $http({
                    url: url,
                    method: 'POST',
                    data:$scope.registObj
                    //,headers: { 'Content-Type': 'application/x-www-form-urlencoded' }//node.js 传输不要
                }).success(function (response) {
                   
                    //alert(response.success)
                    $scope.reset();
                    alert("注册成功，请使用此用户名进行登录。");
                }).error(function () {
                    //alert("error");                  
                    closeLoading();
                })
            }


            $scope.checkRegist = function () {
                showLoading();
                url = "/user/exist";
                $http({
                    url: url,
                    method: 'POST',
                    data: $scope.registObj
                }).success(function (response) {
                    if (response.state == "true") {
                        alert("此登录名已被使用，请使用其他的登录名。");
                        closeLoading();
                    }
                    else {
                        $scope.regist();
                    }
                }).error(function () {
                    alert("error");
                    closeLoading();
                })
            }


            $scope.toHomeSite = function () {
                var pathname = window.location;
                var url= pathname.substring(0, pathname.indexOf("/", 1));
                window.location.href = url;
            }

        });
    </script>
</body>
</html>
